﻿﻿//-----------------------------------------------------------------------
// <copyright file="OtherUserHelper.cs" company="AFS">
// Copyright (c) AFS. All rights reserved.
//
//    This file is part of Chatbox.
//
//    Chatbox is free software: you can redistribute it and/or modify
//    it under the terms of the GNU Lesser General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    any later version.
//
//    Chatbox is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//    GNU Lesser General Public License for more details.
//
//    You should have received a copy of the GNU Lesser General Public License
//    along with Chatbox. If not, see http://www.gnu.org/copyleft/lesser.html
// </copyright>
//----------------------------------------------------------------------- 

namespace ChatBox.DomainObjects.XmlFeedObjects
{
    using System.Collections.Generic;
    using System.Linq;
    using System.Xml.Linq;

    using Utility;

    /// <summary>
    /// Helper methods on other user and lists of them
    /// </summary>
    public static class OtherUserHelper
    {
        /// <summary>
        /// read e2 other users from xml
        /// </summary>
        /// <param name="doc">the xml document</param>
        /// <returns>the contructed object list</returns>
        public static IEnumerable<OtherUser> ToOtherUsers(this XContainer doc)
        {
            var otherUserElements = doc.Elements("otherusers").Elements("user");

            var otherUserList = from otherUser in otherUserElements
                select new OtherUser
                {
                    Administrator = otherUser.Attribute("e2god").ToBoolean(),
                    Committer = otherUser.Attribute("committer").ToBoolean(),
                    ChannelOperator = otherUser.Attribute("chanop").ToBoolean(),
                    ContentEditor = otherUser.Attribute("ce").ToBoolean(),
                    Developer = otherUser.Attribute("edev").ToBoolean(),
                    IsBanned = otherUser.Attribute("borged").ToBoolean(),
                    ExperiencePoints = otherUser.Attribute("xp").Value.ToInteger(),
                    User = otherUser.Element("e2link").ToLink()
                };

            return otherUserList.ToList();
        }
    }
}

